package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Insurancebill;
import cn.wolfcode.crm.domain.PaymentHandling;
import cn.wolfcode.crm.query.ObjectQuery;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.PaymentHandlingObjectQuery;
import cn.wolfcode.crm.service.IClientService;
import cn.wolfcode.crm.service.IInsurancebillService;
import cn.wolfcode.crm.service.IPaymentHandlingService;
import cn.wolfcode.crm.util.CRMConstant;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("paymentHandling")
public class PaymentHandlingController {
    @Autowired
    private IPaymentHandlingService paymentHandlingService;
    @Autowired
    private IInsurancebillService iInsurancebillService;

    @RequiresPermissions("paymentHandling:index")
    @PermissionName("见费出单主页")
    @RequestMapping("index")
    public String index() {
        return "paymentHandling/list";
    }

    @RequiresPermissions("paymentHandling:list")
    @PermissionName("见费出单主页")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(PaymentHandlingObjectQuery qo) {
        PageResult<PaymentHandling> result = paymentHandlingService.query(qo);
        qo.setState(CRMConstant.Insurancebill.STATE_WAIT_PAY);
        return iInsurancebillService.query(qo);
    }
    @RequiresPermissions("paymentHandling:pay")
    @PermissionName("见费出单主页")
    @RequestMapping("pay")
    @ResponseBody
    public JsonResult pay(Insurancebill bill) {
        JsonResult jsonResult = new JsonResult();
        try{
            iInsurancebillService.pay(bill);
        }catch(Exception e){
            e.printStackTrace();
            jsonResult.markErrorMsg("缴费失败");
        }
        return jsonResult;
    }


}
